import React from 'react'
import {Row, Col, Card} from 'antd'
import {LeftOutlined} from '@ant-design/icons';
import '../styles.css'
import api from "../../../api/api";
import axios from "axios";


class VisitDetail extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            title: "新增公司",
            visitingInfo: {
                //审核部门
                companyName: "",//访问公司
                factoryName: "",//访问厂区
                visitingDepartment: "",//访问部门
                auditor: "",//审核人员
                //申请信息
                company: "",//公司名称
                applicationDepartment: "",//部门名称
                name: "",//访客姓名
                phoneNum: "",//手机号码
                carNum: "",//车辆信息
                reason: "",//到访事由
                goods: "",//携带物品
                front: "",//证件照片正面
                back: "",//证件照片反面
                //审核信息
                auditStatus: "",//审核状态
                dismissReason: "",//驳回原因
                //到访信息
                visitState: "",//到访状态
                applicationTime: "",//申请时间
                reviewTime: "",//审核时间
                visitingTime: "",//到访时间
                leaveTime: ""//出厂时间
            },
            visitPartnerInfoList: []
        };
    }

    componentDidMount() {
        console.log("初始化");
        this.props.onRef('visitDetail', this)
    }

    getVisitApplyInfo(selectVisitApplyId) {
        var that = this;
        console.info("获取访客信息selectVisitApplyId=" + selectVisitApplyId);
        let url = api.api_URL + "/admin/visitrecord/queryVisitApplyRecordByRecordId?visitRecordId=" + selectVisitApplyId + "&orgCode=" + localStorage.getItem('orgCode');
        axios.get(url, {
            headers: {
                "Authorization": localStorage.getItem('token'),
                "Content-Type": api.ContentType
            }
        }).then(function (res) {
            if (res.data.code !== 1) {
                alert(res.data.msg);
                return;
            }
            let applyRecord = res.data.data.visitApplyRecord;
            that.setState({
                visitingInfo: {
                    companyName: applyRecord.companyName,
                    factoryName: applyRecord.factoryName,
                    visitingDepartment: applyRecord.deptName,
                    auditor: applyRecord.userName,
                    company: applyRecord.gname,
                    applicationDepartment: applyRecord.userDeptName,
                    name: applyRecord.visitName,
                    visitMobile: applyRecord.visitMobile,
                    phoneNum: applyRecord.userPhone,
                    carNum: applyRecord.carNumber,
                    reason: applyRecord.visitMemo,
                    goods: applyRecord.belongings,
                    front: api.api_URL + `/admin/fileupload/getIDCardStream?urlPath=` + applyRecord.idCardOne,
                    back: api.api_URL + `/admin/fileupload/getIDCardStream?urlPath=` + applyRecord.idCardTwo,
                    auditStatus: applyRecord.type === 1 ? "审核中" : applyRecord.type === 2 ? "已通过" : "已驳回",//审核状态
                    dismissReason: applyRecord.reason,//驳回原因
                    visitState: applyRecord.handleType === 0 || applyRecord.handleType === undefined ? "未到访" : applyRecord.handleType === 1 ? "已到访" : "结束到访",//到访状态
                    applicationTime: applyRecord.createTime,//"2020-03-20 04:00:00",//申请时间
                    reviewTime: applyRecord.createTime,//审核时间
                    visitingTime: applyRecord.arrivalTime,//"2020-03-20 07:00:00",//到访时间
                    leaveTime: applyRecord.outTime//"2020-03-20 20:00:00"//出厂时间
                }
            })
        })
    }

    getVisitPartnerInfoList(selectVisitApplyId) {
        var that = this;
        let url = api.api_URL + "/admin/visitrecord/queryVisitPartnerByVisitRecordId?visitRecordId=" + selectVisitApplyId + "&orgCode=" + localStorage.getItem('orgCode');
        axios.get(url, {
            headers: {
                "Authorization": localStorage.getItem('token'),
                "Content-Type": api.ContentType
            }
        }).then(function (res) {
            if (res.data.code !== 1) {
                alert(res.data.msg);
                return;
            }
            let applyRecord = res.data.data.visitPartnerInfoList;
            that.setState({
                visitPartnerInfoList: applyRecord
            })
        })
    }

    onClickReturnMain = e => {
        this.props.returnMain()
    }

    render() {
        return (
            <div className="girdBg">
                <Row className="searchBox">
                    <Col>
                        <div className="returnBtn" onClick={this.onClickReturnMain}>
                            <LeftOutlined/>
                        </div>
                    </Col>
                </Row>
                <Row className="searchBox">
                    <Col span={24}>
                        <Card title="审核部门" bordered={false}>
                            {/*<p>*/}
                                {/*<span>访问公司:</span>*/}
                                {/*<span>{this.state.visitingInfo.companyName}</span>*/}
                            {/*</p>*/}
                            <p>
                                <span>访问公司:</span>
                                <span>{this.state.visitingInfo.factoryName}</span>
                            </p>
                            <p>
                                <span>访问部门:</span>
                                <span>{this.state.visitingInfo.visitingDepartment}</span>
                            </p>
                            <p>
                                <span>审核人员:</span>
                                <span>{this.state.visitingInfo.auditor}</span>
                            </p>
                        </Card>
                        <Card title="申请信息" bordered={false}>
                            <p>
                                <span>公司名称:</span>
                                <span>{this.state.visitingInfo.company}</span>
                            </p>
                            <p>
                                <span>部门名称:</span>
                                <span>{this.state.visitingInfo.applicationDepartment}</span>
                            </p>
                            <p>
                                <span>访客姓名:</span>
                                <span>{this.state.visitingInfo.name}</span>
                            </p>
                            <p>
                                <span>手机号码:</span>
                                <span>{this.state.visitingInfo.visitMobile}</span>
                            </p>
                            <p>
                                <span>车辆信息:</span>
                                <span>{this.state.visitingInfo.carNum}</span>
                            </p>
                            <p>
                                <span>到访事由:</span>
                                <span>{this.state.visitingInfo.reason}</span>
                            </p>
                            <p>
                                <span>携带物品:</span>
                                <span>{this.state.visitingInfo.goods}</span>
                            </p>
                            <p>
                                <span>证件照片:</span>
                            </p>
                            <div>
                                <img className="cardImg"
                                     style={{marginRight: 30}}
                                     alt="logo"
                                     src={this.state.visitingInfo.front}
                                />
                                <img className="cardImg"
                                     alt="logo"
                                     src={this.state.visitingInfo.back}
                                />
                            </div>
                        </Card>
                        <Card className={this.state.visitPartnerInfoList.length === 0 ? "elementHidden" : "elementShow"}
                              title="同行人员" bordered={false}>
                            {this.state.visitPartnerInfoList.map((item) => {
                                return (
                                    <div>
                                        <p>
                                            <span>姓名:</span>
                                            <span>{item.partnerName}</span>
                                        </p>
                                        <p>
                                            <span>电话:</span>
                                            <span>{item.partnerMobile}</span>
                                        </p>
                                        <p>
                                            <span>证件照片:</span>
                                        </p>
                                        <div>
                                            <img className="cardImg"
                                                 style={{marginRight: 30}}
                                                 alt="logo"
                                                 src={api.api_URL + `/admin/fileupload/getIDCardStream?urlPath=` + item.idCardOne}
                                            />
                                            <img className="cardImg"
                                                 alt="logo"
                                                 src={api.api_URL + `/admin/fileupload/getIDCardStream?urlPath=` + item.idCardTwo}
                                            />
                                        </div>
                                    </div>
                                );
                            })}
                        </Card>
                        <Card title="审核信息" bordered={false}>
                            <p>
                                <span>审核状态:</span>
                                <span>{this.state.visitingInfo.auditStatus}</span>
                            </p>
                            <p className={this.state.visitingInfo.auditStatus === '已驳回' ? "elementShow" : "elementHidden"}>
                                <span>驳回原因:</span>
                                <span>{this.state.visitingInfo.dismissReason}</span>
                            </p>
                        </Card>
                        <Card title="到访信息" bordered={false}>
                            <p>
                                <span>到访状态:</span>
                                <span>{this.state.visitingInfo.visitState}</span>
                            </p>
                            <p>
                                <span>申请时间:</span>
                                <span>{this.state.visitingInfo.applicationTime}</span>
                            </p>
                            {/*<p className={this.state.visitingInfo.auditStatus === '审核中' ? "elementHidden" : "elementShow"}>*/}
                                {/*<span>审核时间:</span>*/}
                                {/*<span>{this.state.visitingInfo.reviewTime}</span>*/}
                            {/*</p>*/}
                            <p className={this.state.visitingInfo.visitState === '已到访' || this.state.visitingInfo.visitState === '结束到访' ? "elementShow" : "elementHidden"}>
                                <span>到访时间:</span>
                                <span>{this.state.visitingInfo.visitingTime}</span>
                            </p>
                            <p className={this.state.visitingInfo.visitState === '结束到访' ? "elementShow" : "elementHidden"}>
                                <span>出厂时间:</span>
                                <span>{this.state.visitingInfo.leaveTime}</span>
                            </p>
                        </Card>
                    </Col>
                </Row>
            </div>
        )
    }
}

export default VisitDetail